package com.feifan.monthhelper.calculate;

import com.blankj.utilcode.util.GsonUtils;
import com.blankj.utilcode.util.LogUtils;
import com.feifan.monthhelper.bean.db.DayRecordBean;
import com.feifan.monthhelper.constant.Constant;

import java.util.Date;

public class MenstrualDayCalculate extends AbstractMenstrualCalculate<DayRecordBean> {

    @Override
    boolean canCalculate(DayRecordBean request) {
        long requestDay = request.createDate.getTime()/(1000 * 60 * 60 * 24);

        long menstrualDay = (getDate().getTime()/(1000 * 60 * 60 * 24));
        System.out.println("requestDay = " + requestDay + "  menstrualDay = " + menstrualDay + "  requestDay - menstrualDay = " + (requestDay - menstrualDay));

        if(requestDay < menstrualDay) {
            return false;
        }
        //经期开始日期之后的周期天数内
        return requestDay - menstrualDay < getMenstrual_period();
//        while (requestDay >= menstrualDay + getSpan_period()) {
//            //如果计算日期在经期开始日期之前，则将经期时间切换到下一个预估周期开始日期
//            menstrualDay += getSpan_period();
//        }
//        System.out.println("requestDay = " + requestDay + "  requestDay - menstrualDay = " + (requestDay - menstrualDay));
//        if(requestDay >= menstrualDay) {
////            LogUtils.d("requestDay >= menstrualDay = " + (Math.abs(requestDay - menstrualDay) % (getMenstrual_period() + getSpan_period()) < getMenstrual_period()));
//            //今天在一年中的天数大于等于 月经期在一年中的天数，则两者间相差的天数对周期间隔和周期时间和进行模运算，小于**周期**天数则为月经期
//            return Math.abs(requestDay - menstrualDay) % (getSpan_period()) < getMenstrual_period();
//        } else {
////            LogUtils.d("requestDay < menstrualDay = " + (Math.abs(requestDay - menstrualDay) % (getMenstrual_period() + getSpan_period()) > getSpan_period()));
//            //今天在一年中的天数小于 月经期在一年中的天数，则两者间相差的天数对周期间隔和周期时间和进行模运算，大于**周期间隔**天数则为月经期(即上一月经周期)
//            return Math.abs(requestDay - menstrualDay) % (getSpan_period()) > getSpan_period();
//        }
    }

    @Override
    DayRecordBean calculate(DayRecordBean request) {
        request.state = Constant.MenstrualState.CACULATE_MENSTRUAL_DAY;
        return request;
    }
}
